package com.topfox.common;

/**
 * 异常类
 */
public class TopException extends RuntimeException{
	private static final long serialVersionUID = 1471447353907832702L;
	private String code;
    private String msg;

    private StringBuilder sbMsg;

    public String getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public TopException(String code, String msg) {
        super(msg);
        this.code = code;
        this.msg = msg;
    }

    public TopException(ResponseCode responseCode){
        this(responseCode.getCode(),responseCode.getMsg());
    }

    public TopException(ResponseCode responseCode, String msg){
        this(responseCode.getCode(),msg);
    }

    public static TopException newInstance2(ResponseCode responseCode){
        ExceptionBuilder exceptionBuilder= create(responseCode.getCode(),null);//new ExceptionBuilder(responseCode.getCode(),null);
        exceptionBuilder.getMsg().append(responseCode.getMsg());
        return new TopException(responseCode, exceptionBuilder.getMsg().toString());
    }

    public static ExceptionBuilder newInstance(ResponseCode responseCode){
        return create(responseCode.getCode(), null);
    }

    public static ExceptionBuilder newInstance(String responseCode){
        return create(responseCode, null);
    }
    private static ExceptionBuilder create(String responseCode, Object target){
        return new ExceptionBuilder(TopException.class,responseCode, target);
    }


}
